<?php class Mod_patient extends CI_Model {
	
	function __construct()
	    {
		parent::__construct();
	    }

	function addComptePatient($compte){
		return $this->db->insert('compte_patient', $compte);
	}
        function getIdCompteByMail($email){
            $sql = "SELECT * FROM compte_patient WHERE EMAIL =?";			
		$Q = $this->db->query($sql,array($email));
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$id=$row['ID_COMPTE_PA'];
			}
		}
		$Q->free_result();
		return $id;
	}
        function addInfoPatient($data){
            return $this->db->insert('patient', $data);
        }
        function getInfoPatient($email) {
		$sql = "SELECT * FROM patient WHERE email = ?";			
		$Q = $this->db->query($sql, array($email));
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$data[]=$row;
			}
		}
		$Q->free_result();
		return $data;
	}
        /*retourner identifiant compte patient*/
        function verifComptePatient($email,$mdp) {
		$sql = "SELECT * FROM compte_patient WHERE email = '$email' AND mdp = '$mdp'";
		$Q = $this->db->query($sql);		
		$id = 0;
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$id = $row['ID_COMPTE_PA'];
			}
		}
		$Q->free_result();
		return $id;
        }
        
        function getPatientByIdCompte($id_compte_pa) {
		$sql = "SELECT * FROM patient WHERE ID_COMPTE_PA = '$id_compte_pa'";
		$Q = $this->db->query($sql);		
		$id_pa = 0;
		if ($Q->num_rows()>0){
			foreach ($Q->result_array() as $row){
				$id_pa = $row['ID_PA'];
			}
		}
		$Q->free_result();
		return $id_pa;
        }
        
}